package com.laikan.reader.bookfriend.adapter;

import android.content.Context;
import android.view.ViewGroup;
import com.laikan.reader.bookfriend.adapter.support.MultiItemTypeSupport;
import com.laikan.reader.bookfriend.holder.LViewHolder;

/**
 * Created by lingyt on 2016/11/18.
 * 作者界面的多条目+footer适配器
 */
public abstract class AutherAdapter<T> extends BaseListAdapter<T> {

    private MultiItemTypeSupport<T> mSupport;


    public AutherAdapter(Context context, int layoutId,MultiItemTypeSupport<T> support) {
        super(context, layoutId);
        this.mSupport = support;
    }

    @Override
    public int getItemViewType(int position) {
        if (position == getItemCount()-1){
            return super.getItemViewType(position);
        }else{
            return mSupport.getItemViewType(position,mDatas.get(position));
        }
    }

    @Override
    public LViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if (viewType == ITEM_TYPE_FOOTER){
            return super.onCreateViewHolder(parent,viewType);
        }else{
            int layoutId = mSupport.getLayoutId(viewType);
            return LViewHolder.createViewHolder(mContext,layoutId);
        }
    }

    @Override
    protected abstract void convert(LViewHolder holder, T t);
}
